<?php

namespace App\Services;

use App\Models\Banner;
use App\Models\BaseModel;

class BannerService extends BaseService
{
    /**
     * Banner列表
     * @param $pageSize
     * @param $bannerType
     * @return array
     */
    public function list($pageSize, $bannerType)
    {
        // 设置对象
        $model = Banner::query();
        // banner类型
        if ($bannerType) {
            $model = $model->where('banner_type', $bannerType);
        }
        // 状态
        $model = $model->where('status', BaseModel::STATUS_ENABLE);
        // 获取列表
        $list = $model
            ->orderBy('sort', 'desc')
            ->orderBy('id', 'desc')
            ->limit($pageSize)
            ->get(['id', 'banner_img', 'link'])
            ->toArray();

        foreach ($list as &$item) {
            $item['banner_img'] = storage($item['banner_img']);
        }

        return $list;
    }
}
